package com.cloudxingkong.dianyinke.Student.Adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cloudxingkong.dianyinke.R;
import com.cloudxingkong.dianyinke.Student.bean.QbfkEntity;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by ningfei on 2016/5/9.
 */
public class DfkAdapter extends BaseAdapter{
    private List<QbfkEntity.ListBean> data;
    private Context context;
    private onCallback onCallbacks;


    public DfkAdapter(List<QbfkEntity.ListBean> data, Context context, DfkAdapter.onCallback onCallbacks) {
        this.data = data;
        this.context = context;
        this.onCallbacks = onCallbacks;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView==null){
            convertView = View.inflate(context, R.layout.item_dfk,null);
            holder = new ViewHolder();
            holder.tv_dfk_type = (TextView) convertView.findViewById(R.id.tv_dfk_type);
            holder.tv_dfk_title = (TextView) convertView.findViewById(R.id.tv_dfk_title);
            holder.tv_dfk_guige = (TextView) convertView.findViewById(R.id.tv_dfk_guige);
            holder.tv_dfk_jifen = (TextView) convertView.findViewById(R.id.tv_dfk_jifen);
            holder.tv_dfk_shifukuan = (TextView) convertView.findViewById(R.id.tv_dfk_shifukuan);
            holder.tv_dfk_quxiaodingdan = (TextView) convertView.findViewById(R.id.tv_dfk_quxiaodingdan);
            holder.tv_dfk_zhifu = (TextView) convertView.findViewById(R.id.tv_dfk_zhifu);
            holder.iv = (ImageView) convertView.findViewById(R.id.iv_dfk_qianbi);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        onCallbacks.onClick_zhifu(holder.tv_dfk_zhifu, position);
        onCallbacks.onClick_quxiaodingdan(holder.tv_dfk_quxiaodingdan, position);

        holder.tv_dfk_type.setText(data.get(position).getName()+"");//名称
        holder.tv_dfk_title.setText(data.get(position).getNote()+"");//标题
        holder.tv_dfk_guige.setText(data.get(position).getSize()+"");//规格
        holder.tv_dfk_jifen.setText(data.get(position).getTotalpoints() + "");//使用积分
        holder.tv_dfk_shifukuan.setText(data.get(position).getMoney() + "");//实付款
        ImageLoader.getInstance().displayImage(data.get(position).getPic() + "", holder.iv);


        return convertView;
    }
    private class ViewHolder{
        private TextView tv_dfk_type,tv_dfk_title,tv_dfk_guige,tv_dfk_jifen,tv_dfk_shifukuan,tv_dfk_quxiaodingdan,tv_dfk_zhifu;
        private ImageView iv;
    }
    public interface onCallback{
        void onClick_quxiaodingdan(TextView tv1,int position);
        void onClick_zhifu(TextView tv2,int position);
    }
}
